<?php
namespace App\Exception;

use EasySwoole\Core\Http\AbstractInterface\ExceptionHandlerInterface;
use EasySwoole\Core\Http\Request;
use EasySwoole\Core\Http\Response;

class ExceptionHandler implements ExceptionHandlerInterface
{
    public function handle( \Throwable $exception, Request $request, Response $response )
    {
        $response -> withStatus(200);
        if($exception->getCode() == 200){
            $response -> write($exception -> getMessage());
        }else{
            $res = [
                'code' => 500,
                'msg'  => 'Error on line '.$exception->getLine().' in '.$exception->getFile().': <b>'.$exception->getMessage()
            ];
            $response -> write(json_encode($res));
        }
    }
}